package com.edfu.core.identitymgt.service.ws;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.edfu.core.identitymgt.service.api.IIdentityMgtService;
import com.edfu.core.identitymgt.vo.User;


@Path("/")
@Produces( { MediaType.APPLICATION_JSON })
@Consumes(MediaType.APPLICATION_JSON)
@WebService(targetNamespace = "http://com.edfu.core.identitymgt.service.ws.IdentityMgtService")
@Component
public class IdentityMgtServiceDelegate  {

	private static final Logger LOGGER = LoggerFactory.getLogger(IdentityMgtServiceDelegate.class);
	
	@Autowired
	IIdentityMgtService identityMgtService;
	
	@POST
	@Path("/users")
	@WebMethod(operationName = "addUser")
	public Response registerUser(User user) {
		identityMgtService.addUser(user);
		LOGGER.debug("User addition succesful");
		return Response.ok().build();
	}
	
	@PUT
	@Path("/users")
	@WebMethod(operationName = "updateUser")
	public Response updateUser(User user) {
		identityMgtService.addUser(user);
		LOGGER.debug("User updation succesful");
		return Response.ok().build();
	}
	
	@GET
	@Path("/users/{userid}")
	@WebMethod(operationName = "getUser")
	public User getUserByID(@PathParam(value = "userid") String userID) {
		return identityMgtService.getUser(userID);
	}
	
}
